<?php include (dirname(__FILE__)."/../include/header.php"); ?>
<?php if(!isset($_SESSION['_user'])){header("location:../user_login.php");}?>
<?php if(isset($_POST['review_score1'])){
	//添加点单评价.
	$order_id=$_REQUEST['order_id'];
	$order_speed=$_REQUEST['speed'];
	$review_score1=$_REQUEST['review_score1'];
	$review_score2=$_REQUEST['review_score2'];
	$review_score3=$_REQUEST['review_score3'];
	$integral=$_REQUEST['integral'];
	$sql="INSERT INTO `zy_order_review`(`user_id`,`order_id`,`order_speed`,`review_score1`,`review_score2`,`review_score3`,`review_content`) VALUES ('".$_SESSION['_user']['user_id']."','$order_id','$order_speed','$review_score1','$review_score2','$review_score3','');";
	mysql_query($sql);
	$sql2="update zy_user set integral=integral+".$integral." where user_id=".$_SESSION['_user']['user_id'];
	mysql_query($sql2);
	$sql3="update zy_order set order_status=2 where ord_id=".$order_id;
	mysql_query($sql3);
	header("location:#".$order_id);
}?>
<?php
$start_date=date("Y-m-d",strtotime("-1 month",time()))." 00:00:00";
$end_date= date("Y-m-d",time())." 23:59:59";
$method=$_REQUEST['method'];
$sql="select * from zy_order where ";
if($method=="one-month"){
$where="order_time between '$start_date' and '$end_date'";
}else if($method=="before-month"){
$where="order_time < '$start_date'";
}
else if($method=="unrated"){
$where="order_status<2";
}
$sql=$sql.$where." AND user_id='".$_SESSION['_user']['user_id']."' order by order_time desc";
?>
<div class="container">
<ul class="breadcrumb">
   <li><a href="<?php echo SITE_ROOT; ?>">返回首页</a><span class="divider">/</span></li>
  <li><a href="<?php echo SITE_ROOT; ?>/user/order_list.php?method=one-month">点单中心</a></li>
</ul>
<div class="row">
  <div class="span12 wash-paper user-center profile">
    <div class="row">
      <div class="span3">
        <?php include (dirname(__FILE__)."/../include/user/left.php"); ?>
        <div class="span9">
          <div class="main-content">
            <div class="content-header">
              <h3> <?php $result = mysql_query($sql);
$number = mysql_num_rows($result); 
// echo $number;
if(isset($_SESSION['_user'])){
if($method=="one-month"){ echo "最近一个月的点单共".$number."单";}
else if($method=="before-month"){echo "一个月前的点单共".$number."单";}
else if($method=="unrated"){echo "未点评的点单共".$number."单";}
 } ?>
			   </h3>
            </div>
            <div class="content-inner">
              <div class="alert rating-time-limit-tips"> 为了更准确地统计餐厅送餐速度，完善点评体系，我们将送餐速度点评时间限定为3小时内。请收到美食后尽快点评~ </div>
              <div class="order-list">
			  <?php $result = mysql_query($sql);
			  // echo $sql;
				if(isset($_SESSION['_user']))
			  	{
				while($zy_order=mysql_fetch_array($result)){
				$number=mysql_num_rows($result);
				// echo $number;	
			  ?>
			  <?php
			  	$sql="select * from zy_shop where shop_id=".$zy_order['shop_id'];
			  	$shop_result=mysql_query($sql);
			  		if($shop_arr=mysql_fetch_array($shop_result)){
			  			$shop=$shop_arr;
			  		}
			  ?>
                <div class="order-block" id="<?php echo $zy_order['ord_id'];?>" ">
                  <div class="order-header">
                    <div class="line-one">
                      <div class="status-wrapper">
                        <div class="status orange"><?php/* switch ($zy_order['order_status']){
                        	case 0:
							  echo "等待餐厅确认";
							break;
							case 1:
							  echo "正在配送";
							break;
							case 2:
							  echo "已收货";
							break;
							case 3:
							  echo "已点评";
							break;
                        }*/?>@<a   href="<?php echo SITE_ROOT."/index_shop.php?shop_id=".$zy_order['shop_id']; ?>" target="_blank"><?php echo $shop['shop_name'];?></a>
                        </div>
                      </div>
                    </div>
                    <div class="line-two">
                      <table class="table table-condensed">
                        <tbody>
                          <tr>
                            <td class="col1"><span class="item-name">点单号:</span> <?php echo $zy_order['ord_id'];?></td>
                            <td class="col2"><span class="item-name">下单时间:</span><?php echo $zy_order['order_time'];?></td>
                            <td class="col3"><span class="item-name">餐厅电话:</span> <?php echo $shop['shop_phone'];?></td>
                          </tr>
                          <tr>
<?php 
                            if($zy_order['add_id']!=0){
                                $query="select * from zy_address where add_id = '".$zy_order['add_id']."'"; 
                            }else{
                                $query="select * from zy_address where user_id='".$zy_order['user_id']."' and create_time='".$zy_order['create_time']."'";
                            }
//echo $query;
                            $rs=mysql_query($query);
                            while($zy_address=mysql_fetch_array($rs)){
                               
								
			  				?>
			  				 <td class="col1"><span class="item-name">点单地址:</span><?php echo $zy_address['address'];?></td>
                            <td class="col2"><span class="item-name">联系电话:</span><?php echo $zy_address['phone'];?></td>
                            <?php }?>
                            <td class="col3"><span class="item-name">点单备注:</span><?php echo $zy_order['remark'];?> </td>
                          </tr>
                        </tbody>
                      </table>
                    </div>
                  </div>
                  <div class="order-table-wrapper">
                    <table class="order-table table table-striped">
                      <thead>
                        <tr>
                          <th class="col-name">美食篮子</th>
                          <th class="col-rating" style="text-align:center; color:#333;">点评菜品的美味程度</th>
                          <th class="col-price">单价</th>
                          <th class="col-quantity">数量</th>
                          <th class="col-sub-total">小计</th>
                        </tr>
                      </thead>
					 
                      <tbody>
					    <?php 
				  $sql2="select * from zy_item where order_id ='".$zy_order['ord_id']."'";
				  $result2 = mysql_query($sql2);
				  $num = mysql_num_rows($result2);
				  while($zy_item=mysql_fetch_array($result2)){?>
                        <tr >
                          <td class="col-name"><span><?php echo $zy_item['food_name']?></span> </td>
                          <td class="col-rating" style="text-align:center;">
						<?php 
							$food_review_sql="select * from zy_food_review where order_id=".$zy_order['ord_id']." and food_id=".$zy_item['food_id'];
							$food_review_result= mysql_query($food_review_sql);
							if($food_review_result=mysql_fetch_array($food_review_result)){?>
								
							<div class="foodreview disabled" id="foodreview-<?php echo $zy_order['ord_id'];?>-<?php echo $zy_item['food_id']?>" title="点击星星以完成评分">
					        	<?php for($i=1;$i<=$food_review_result['food_score'];$i++){?>
					        	<span class="light">&nbsp;</span>
					        	<?php }?>
					        	<?php for($i=1;$i<=5-$food_review_result['food_score'];$i++){?>
					        	<span class="dark">&nbsp;</span>
					        	<?php }?>
			       		    </div>
						<?php 		
							}else{
						?>
						
				        <div class="foodreview" id="foodreview-<?php echo $zy_order['ord_id'];?>-<?php echo $zy_item['food_id']?>" title="点击星星以完成评分">
				        	<span class="dark">&nbsp;</span>
				            <span class="dark">&nbsp;</span>
				            <span class="dark">&nbsp;</span>
				            <span class="dark">&nbsp;</span>
				            <span class="dark">&nbsp;</span>
				        </div>
				    	<?php } ?>
						</td>
                          <td class="col-price"><?php echo $zy_item['food_price'] ?></td>
                          <td class="col-quantity"><?php echo $zy_item['count'] ?></td>
                          <td class="col-sub-total"><?php echo $zy_item['subtotal']?></td>
                        </tr>
                  	<?php  } ?>
						<tr>
                          <td class="col-name"><span>外送费</span> </td>
                          <td class="col-rating"></td>
                          <td class="col-price"></td>
                          <td class="col-quantity"></td>
                          <td class="col-sub-total">20.00</td>
                        </tr>
                      </tbody>
                    </table>
                    <table class="order-table total-table table table-striped">
                      <tfoot>
                        <tr>
                          <td class="col-name">合计</td>
                          <td class="col-rating"></td>
                          <td class="col-price"></td>
                          <td class="col-quantity"><?php echo $num;?></td>
                          <td class="col-sub-total"><?php echo number_format($zy_order['totalPrice']+20.00,2);?></td>
                        </tr>
                      </tfoot>
                    </table>
                    <h4>点单点评</h4>
                  </div>
                  <!--点评-->
                  <?php
                  $r_sql="select * from zy_order_review where order_id=".$zy_order['ord_id'];
                  $review_arr=mysql_query($r_sql);
                  if($result_review=mysql_fetch_array($review_arr)){ ?>
                  <div class="reviews">
                   
					<div class="remark">
				    	<div class="remarktxt">
				        	<span>菜品的美味程度：</span>
				        </div>
				        <div class="remarkstart reviewed disabled" id="review-<?php echo $zy_order['ord_id'];?>-score1" title="<?php echo $result_review['review_score1'];?>分" title="点击星星以完成评分">
				        	<?php for($i=1;$i<=$result_review['review_score1'];$i++){?>
				        	<span class="light">&nbsp;</span>
				        	<?php }?>
				        	<?php for($i=1;$i<=5-$result_review['review_score1'];$i++){?>
				        	<span class="dark">&nbsp;</span>
				        	<?php }?>
				        </div>
				    </div>
				</div>
				<div class="reviews">
					<div class="remark">
				    	<div class="remarktxt">
				        	<span>菜品与描述相符：</span>
				        </div>
				        <div class="remarkstart reviewed disabled" id="review-<?php echo $zy_order['ord_id'];?>-score2" title="<?php echo $result_review['review_score2'];?>分" title="点击星星以完成评分">
				        	<?php for($i=1;$i<=$result_review['review_score2'];$i++){?>
				        	<span class="light">&nbsp;</span>
				        	<?php }?>
				        	<?php for($i=1;$i<=5-$result_review['review_score2'];$i++){?>
				        	<span class="dark">&nbsp;</span>
				        	<?php }?>
				        </div>
				    </div>
				</div>
				<div class="reviews">
					<div class="remark">
				    	<div class="remarktxt">
				        	<span>配送员服务态度：</span>
				        </div>
				        <div class="remarkstart reviewed disabled" id="review-<?php echo $zy_order['ord_id'];?>-score3" title="<?php echo $result_review['review_score3'];?>分" title="点击星星以完成评分">
				        	<?php for($i=1;$i<=$result_review['review_score3'];$i++){?>
				        	<span class="light">&nbsp;</span>
				        	<?php }?>
				        	<?php for($i=1;$i<=5-$result_review['review_score3'];$i++){?>
				        	<span class="dark">&nbsp;</span>
				        	<?php }?>
				        </div>
				    </div>
				</div>
				  <div class="col-title"> 送餐速度： <?php echo $result_review['order_speed']?>分钟 </div>
                  <?php }else{?>
                 <div class="reviews">
					<div class="remark">
				    	<div class="remarktxt">
				        	<span>菜品的美味程度：</span>
				        </div>
				        <div class="remarkstart" id="review-<?php echo $zy_order['ord_id'];?>-score1"  title="点击星星以完成评分">
				        	<span class="dark">&nbsp;</span>
				            <span class="dark">&nbsp;</span>
				            <span class="dark">&nbsp;</span>
				            <span class="dark">&nbsp;</span>
				            <span class="dark">&nbsp;</span>
				        </div>
				    </div>
				</div>
				 <div class="reviews" >
					<div class="remark">
				    	<div class="remarktxt">
				        	<span>菜品与描述相符：</span>
				        </div>
				        <div class="remarkstart" id="review-<?php echo $zy_order['ord_id'];?>-score2"  title="点击星星以完成评分">
				        	<span class="dark">&nbsp;</span>
				            <span class="dark">&nbsp;</span>
				            <span class="dark">&nbsp;</span>
				            <span class="dark">&nbsp;</span>
				            <span class="dark">&nbsp;</span>
				        </div>
				    </div>
				</div>
				<div class="reviews" >
					<div class="remark">
				    	<div class="remarktxt">
				        	<span>配送员服务态度：</span>
				        </div>
				        <div class="remarkstart" id="review-<?php echo $zy_order['ord_id'];?>-score3"  title="点击星星以完成评分">
				        	<span class="dark">&nbsp;</span>
				            <span class="dark">&nbsp;</span>
				            <span class="dark">&nbsp;</span>
				            <span class="dark">&nbsp;</span>
				            <span class="dark">&nbsp;</span>
				        </div>
				        
				    </div>
				</div>
				 <div class="line-one">
				 <form action="" method="post" id="form-<?php echo $zy_order['ord_id'];?>">
                      <div class="col-title"> 点评送餐速度： </div>
                      <div class="col-content">
                      <input type="text" name="speed" value="" id="speed" />分钟<br />
                    </div>
                    
                     <input type="hidden" name="review_score1" id="review_<?php echo $zy_order['ord_id'];?>_score1" />
                      <input type="hidden" name="review_score2" id="review_<?php echo $zy_order['ord_id'];?>_score2" />
                      <input type="hidden" name="review_score3" id="review_<?php echo $zy_order['ord_id'];?>_score3" />
                      <input type="hidden" name="integral" value="<?php echo $zy_order['totalPrice']*10;?>" />
                       <input type="hidden" name="order_id" value="<?php echo $zy_order['ord_id'];?>" />
                      <input type="button" id="speed-submit" onclick="javascript:order_review('<?php echo $zy_order['ord_id'];?>');" class="btn" value="确认点评"/>
                   </form>
				</div>
                   <!//--点评-->
                   <?php } ?>
                </div>
				<?php } 
			  	}?>
        </div>
      </div>
    </div>
  </div>
  <a id="back-to-top" href="javascript:void(0);">
  <div class="backtotop"></div>
  </a> </div>
<?php include (dirname(__FILE__)."/../include/footer.php"); ?>
<script type="text/javascript">
	//公共变量
	var first_level = "很差";
	var second_level = "较差";
	var third_level = "还行";
	var fifth_level = "推荐";
	var sixth_level = "力荐";
	
	//鼠标经过星星评分时绑定时间
	function pubmark(obj){
		var father_obj = $(obj);//父对象
		var son_objs = father_obj.children("span");//所有子对象绑定事件
		var index = son_objs.index()+1;
		switch(index) { 
			case 1: 
				giveMark(son_objs, first_level, index);
				break; 
			case 2: 
				giveMark(son_objs, second_level, index);
				break; 
			case 3: 
				giveMark(son_objs, third_level, index);
				break; 
			case 4 : 
				giveMark(son_objs, fifth_level, index);
				break; 
			case 5: 
				giveMark(son_objs, sixth_level, index);
				break;
			default:
				giveMark(son_objs, fifth_level,  4);
			}
		giveStart(son_objs,index);
		son_objs.mouseover(function(){
				var curr_sobj = $(this);
				//curr_sobj.parent().next().html("<span>已评价</span>");
				curr_sobj.mouseout(function (){
					judgeStart(curr_sobj);	
					//alert($(this).index()+1);
					//alert($(this).parent().attr("id"));
					var value = $(this).parent().attr("id").split('-');
					if(value[0]=="review"){
                        $("#"+value[0]+"_"+value[1]+"_"+value[2]).attr("value",($(this).index()+1));
					}else if(value[0]=="foodreview"){
						$.ajax({
				            type: "post",
				            url: "include/zy_function.php",
							data:{method:value[0],order_id:value[1],food_id:value[2]},
				            dataType: "json",
				            success: function(){
				            	//curr_sobj.removeAttr("onmousemove");
				            	alert("评论成功");
				            }
				         });
					}
				});
			}).hover(			
				function(){//鼠标悬停事件
                    var curr_sobj = $(this);
					judgeStart(curr_sobj);//判断几颗星
				});
	}
	//判断几颗星
	function judgeStart(obj){
		var marks =  obj.parent().children("span");
		marks.each(function (){
			var curr_obj = $(this);
			curr_obj.removeClass("light").addClass("dark");
		});
		/*var index = obj.index()+1;
		switch(index) { 
			case 1: 
				giveMark(obj, first_level, index);
				break; 
			case 2: 
				giveMark(obj, second_level, index);
				break; 
			case 3: 
				giveMark(obj, third_level, index);
				break; 
			case 4 : 
				giveMark(obj, fifth_level, index);
				break; 
			case 5: 
				giveMark(obj, sixth_level, index);
				break;
			default:
				giveMark(obj, fifth_level,  4);
			} */
		
	}
	
	//给分数
	function giveMark(obj, str, index){
		//obj.parent().next().children(".marktxt").html(str);
		//obj.parent().next().children(".marknum").html(index);
		giveStart(obj, index);//给星星
	}

function giveStart(obj, num){
	var marks =  obj.parent().children("span");
	marks.each(function (){
		var curr_obj = $(this);
		var curr_index = curr_obj.index()+1;
		if(curr_index <= num){
			curr_obj.removeClass("dark").addClass("light");
			
		}else{
			curr_obj.removeClass("light").addClass("dark");
		}
	});
}
function order_review(order_id){
	var b=true;
	$("#"+order_id+".foodreview").each(function(){
			if(!$(this).hasClass("disabled")){
				alert("请先给点单里的餐品评分.");
				alert($(this).parent().parent().parent().html());
				b=false;
				return b;
			}
		});
	$("#form-"+order_id+" input").each(function(){
		if(b){
			if($(this).attr("value")==""){
				alert("请填写评分.");
				b=false;
				return b;
			}
		}
		
	});
	if(b){
		$("#form-"+order_id).submit();
	}
	
}
$(document).ready(function(){
	//单品鼠标滑过星星上色.
	$(".foodreview span").mouseover(function(){
		if(!$(this).parent().hasClass("disabled")){
			giveStart($(this),$(this).index()+1);
		}
	});
	//单品鼠标移开星星变灰.
	$(".foodreview").mouseout(function(){
		if(!$(this).hasClass("disabled")){
			giveStart($(this).children(),0);
		}
	});
	//单品鼠标点击AJAX提交评分数据.
	$(".foodreview span").click(function(){
	if($(this).parent().hasClass("disabled")){
			return false;
	}
	var value = $(this).parent().attr("id").split('-');
	var review=$(this).parent();
		$.ajax({
			type: "post",
			url: "../include/zy_function.php",
			data:{method:value[0],order_id:value[1],food_id:value[2],food_score:($(this).index()+1)},
			dataType: "json",
			success: function(){
			review.addClass("disabled");
			}
		});
	});
	//订单点评鼠标滑过星星上色.
	$(".remarkstart span").mouseover(function(){
		if(!$(this).parent().hasClass("disabled")){
			giveStart($(this),$(this).index()+1);
		}
	});
	//订单点评鼠标移开星星变灰.
	$(".remarkstart").mouseout(function(){
		if(!$(this).hasClass("disabled")){
			giveStart($(this).children(),0);
		}
	});
	//订单点评鼠标点击赋值.
	$(".remarkstart span").click(function(){
		if(!$(this).parent().hasClass("reviewed")){
			giveStart($(this),$(this).index()+1);
		}
		var value = $(this).parent().attr("id").split('-');
		var id=value[0]+"_"+value[1]+"_"+value[2];
		$("#"+id).attr("value",$(this).index()+1);
		var review=$(this).parent();
		review.addClass("disabled");
		//review.html(review.html()+"<div>"+($(this).index()+1)+"分</div>");
	});
});
</script>
